User
<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import * as echarts from 'echarts'

require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions(this.chartData)
    },
    setOptions({
                 dateData,
                 collection1,
                 collection2,
                 collection3,
                 collection4,
                 collection5,
                 collection6,
                 collection7,
                 collection8,
                 collection9,
                 collection10,

               } = {}) {
      this.chart.setOption({
        xAxis: {
          data: dateData,
          boundaryGap: false,
          axisTick: {
            show: false
          }
        },
        grid: {
          left: 10,
          right: 10,
          bottom: 20,
          top: 30,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          data: ['通威股份', '隆基绿能', '特变电工', '晶科能源', '天合光能', '晶奥科技', 'TCL中环', '正泰电器', '阳光能源', '协鑫科技']
        },
        series: [{
          name: '通威股份', itemStyle: {
            normal: {
              color: '#FF005A',
              lineStyle: {
                color: '#FF005A',
                width: 2
              }
            }
          },
          smooth: true,
          type: 'line',
          data: collection1,
          animationDuration: 2800,
          animationEasing: 'cubicInOut'
        },
          {
            name: '隆基绿能',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#3888fa',
                lineStyle: {
                  color: '#3888fa',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection2,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },
          {
            name: '特变电工',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#4c9e44',
                lineStyle: {
                  color: '#4c9e44',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection3,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },
          {
            name: '晶科能源',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#ed7547',
                lineStyle: {
                  color: '#ed7547',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection4,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: '天合光能',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#4c9e44',
                lineStyle: {
                  color: '#4c9e44',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection5,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: '晶奥科技',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#f2be48',
                lineStyle: {
                  color: '#f2be48',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection6,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: 'TCL中环',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#2b2b2b',
                lineStyle: {
                  color: '#2b2b2b',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection7,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: '正泰电器',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#7732b4',
                lineStyle: {
                  color: '#7732b4',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection8,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: '阳光能源',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#4c9e44',
                lineStyle: {
                  color: '#4c9e44',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection9,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }, {
            name: '协鑫科技',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#e94d60',
                lineStyle: {
                  color: '#e94d60',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: collection10,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },
        ]
      })
    }
  }
}
</script>
